<template>
  <div id="app">
    <button @click="initMqtt">init mqtt</button>
  </div>
</template>

<script>

export default {
  name: 'App',
  methods:{
    initMqtt() {
      const mqtt = require("mqtt");
      const client = mqtt.connect("ws://121.40.115.160:7024/mqtt", {
        clientId: "abc",
        username: "abc",
        password: "abc",
        reconnectPeriod: 0,
      });
      client.on("connect", function() {
        console.log("connect");
      });

      client.on("close", function() {
        console.log("close");
      });

      client.on("error", function(error) {
        console.log(error);
      });
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
